package leecode;

import java.util.ArrayList;
import java.util.List;

public class LeetCode35 {
    public void flatten(TreeNode root) {
        List<TreeNode>list=new ArrayList<>();
        preorderTraversal(root, list);
        int size=list.size();
        for (int i = 1; i < size; i++) {
            TreeNode cur=list.get(i-1);
            TreeNode curr=list.get(i);
            cur.left=null;
            cur.right=curr;
        }
    }

    private void preorderTraversal(TreeNode root, List<TreeNode> list) {
        if(list==null){
            return;
        }
        list.add(root);
        preorderTraversal(root.left,list);
        preorderTraversal(root.right,list);
    }
}
